<title>短信发送日志</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsSms/GetIndex" lay-done="layui.data.done(d);">

</script>
<div class="table-body">
    <table id="LAY-app-CoreCmsSms-tableBox" lay-filter="LAY-app-CoreCmsSms-tableBox"></table>
</div>

<script type="text/html" id="LAY-app-CoreCmsSms-toolbar">
    <div class="layui-form coreshop-toolbar-search-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="mobile" id="mobile" placeholder="请输入手机号码" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="code">
                        <option value="">请选择类型</option>
                        <optgroup label="短信消息">
                            {{# layui.each(indexData.smsMessageTypes, function(index, item){ }}
                            <option value="{{ item.value }}">{{ item.description }}[{{ item.title }}]</option>
                            {{# }); }}
                        </optgroup>
                        <optgroup label="平台消息">
                            {{# layui.each(indexData.platformMessageTypes, function(index, item){ }}
                            <option value="{{ item.value }}">{{ item.description }}[{{ item.title }}]</option>
                            {{# }); }}
                        </optgroup>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="isUsed" id="isUsed">
                        <option value="">请选择是否使用</option>
                        <option value="True">是</option>
                        <option value="False">否</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline core-time-input">
                    <input type="text" name="createTime" id="searchTime-CoreCmsSms-createTime" placeholder="请选择创建时间" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsSms-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="LAY-app-CoreCmsSms-pagebar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="batchDelete"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
    </div>
</script>
<script type="text/html" id="LAY-app-CoreCmsSms-tableBox-bar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    var indexData;
    layui.data.done = function (d) {
        indexData = d.data;
        layui.use(['index', 'table', 'laydate', 'util', 'coreHelper'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , view = layui.view;


                var searchwhere;
                //监听搜索
                form.on('submit(LAY-app-CoreCmsSms-search)',
                    function (data) {
                        var field = data.field;
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsSms-tableBox', { where: field });
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsSms-tableBox',
                    url: layui.setter.apiUrl + 'Api/CoreCmsSms/GetPageList',
                    method: 'POST',
                    toolbar: '#LAY-app-CoreCmsSms-toolbar',
                    pagebar: '#LAY-app-CoreCmsSms-pagebar',
                    className: 'pagebarbox',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-127',//无面包屑127,搜索框189,1行62
                    page: true,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            { type: "checkbox", fixed: "left" },
                            { field: 'id', title: '序列', sort: false, width: 60 },
                            { field: 'mobile', title: '手机号码', sort: false, width: 105 },
                            { field: 'code', title: '发送编码', sort: false, width: 150 },
                            { field: 'params', title: '参数', sort: false, width: 105 },
                            { field: 'contentBody', title: '内容', sort: false },
                            { field: 'ip', title: 'ip', sort: false, width: 105 },
                            { field: 'isUsed', title: '是否使用', width: 105, templet: '#switch_isUsed', sort: false, unresize: true },
                            { field: 'createTime', title: '创建时间', width: 130, sort: false },
                            { width: 82, align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-CoreCmsSms-tableBox-bar' }
                        ]
                    ]
                });
                //监听排序事件
                table.on('sort(LAY-app-CoreCmsSms-tableBox)', function (obj) {
                    table.reloadData('LAY-app-CoreCmsSms-tableBox', {
                        initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                        where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                            orderField: obj.field, //排序字段
                            orderDirection: obj.type //排序方式
                        }
                    });
                });
                //监听行双击事件
                table.on('rowDouble(LAY-app-CoreCmsSms-tableBox)', function (obj) {
                    //查看详情
                    doDetails(obj);
                });
                //头工具栏事件
                table.on('pagebar(LAY-app-CoreCmsSms-tableBox)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'batchDelete':
                            doBatchDelete(checkStatus);
                            break;
                        case 'selectExportExcel':
                            doSelectExportExcel(checkStatus);
                            break;
                        case 'queryExportExcel':
                            doQueryExportexcel();
                            break;
                    };
                });
                //监听工具条
                table.on('tool(LAY-app-CoreCmsSms-tableBox)',
                    function (obj) {
                        if (obj.event === 'del') {
                            doDelete(obj);
                        }
                    });

                //执行单个删除
                function doDelete(obj) {
                    layer.confirm('确定删除吗？删除后将无法恢复。', function (index) {
                        coreHelper.Post("Api/CoreCmsSms/DoDelete", { id: obj.data.id }, function (e) {
                            table.reloadData('LAY-app-CoreCmsSms-tableBox');
                            layer.msg(e.msg);
                        });
                    });
                }
                //执行批量删除
                function doBatchDelete(checkStatus) {
                    var checkData = checkStatus.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择要删除的数据');
                    }
                    layer.confirm('确定删除吗？删除后将无法恢复。',
                        function (index) {
                            var delidsStr = [];
                            layui.each(checkData,
                                function (index, item) {
                                    delidsStr.push(item.id);
                                });
                            coreHelper.Post("Api/CoreCmsSms/DoBatchDelete", { id: delidsStr }, function (e) {
                                table.reloadData('LAY-app-CoreCmsSms-tableBox');
                                layer.msg(e.msg);
                            });
                        });
                }
                //执行查询条件导出excel
                function doQueryExportexcel() {
                    layer.confirm('确定根据当前的查询条件导出数据吗？',
                        function (index) {
                            var field = searchwhere;
                            coreHelper.PostForm("Api/CoreCmsSms/QueryExportExcel", field, function (e) {
                                if (e.code === 0) {
                                    window.open(e.data);
                                } else {
                                    layer.msg(e.msg);
                                }
                            });
                        });
                }
                //执行选择目录导出数据
                function doSelectExportExcel(checkStatus) {
                    var checkData = checkStatus.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择您要导出的数据');
                    }
                    layer.confirm('确定导出选择的内容吗？',
                        function (index) {
                            var delidsStr = [];
                            layui.each(checkData,
                                function (index, item) {
                                    delidsStr.push(item.id);
                                });
                            layer.close(index);
                            coreHelper.Post("Api/CoreCmsSms/SelectExportExcel", { id: delidsStr }, function (e) {
                                if (e.code === 0) {
                                    window.open(e.data);
                                } else {
                                    layer.msg(e.msg);
                                }
                            });
                        });
                }

                laydate.render({
                    elem: '#searchTime-CoreCmsSms-createTime',
                    type: 'datetime',
                    range: '到',
                });
                //重载form
                form.render();


            });
    };
</script>

<!--设置是否使用-->
<script type="text/html" id="switch_isUsed">
    <input type="checkbox" disabled="disabled" name="switch_isUsed" value="{{d.id}}" lay-skin="switch" lay-text="已使用|未使用" {{ d.isUsed ? 'checked' : '' }}>
</script>